package com.tal.jzb.service.impl;

import com.tal.jzb.entity.User;
import com.tal.jzb.repository.UserRepository;
import com.tal.jzb.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiefengsong
 * @date 2019-01-24 10:12
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    UserRepository userRepository;

    @Override
    public List<User> findUserByName(String name) {
        List<User> userList = userRepository.findByNameOrderByIdDesc(name);
        log.info("通过姓名:{},查询记录数:{}", name, userList.size());
        return userList;
    }

    @Override
    public String getUserById(Integer id) {
        User user = userRepository.getOne(id);
        return user.getName();
    }
}
